<?php
namespace Admin\Controller;
use Think\Controller;
class AjaxController extends Controller {
    //验证码图片
    public function getcode(){
            //$verify = new \Think\Verify();
            // $verify->fontSize = 18;
            // $verify->length   = 4;
            // $verify->imageW   = 120;
            // $verify->imageH   = 30;
            // $verify->useNoise = false;
            $config = array(
                'fontSize'    =>    14,    // 验证码字体大小
                'length'      =>    4,    // 验证码字数
                'imageW'      =>    130,    // 验证码宽
                'imageH'      =>    40,     // 验证码高
                'useNoise'    =>    false, // 关闭验证码杂点
            );
            ob_clean();
            $verify = new \Think\Verify($config);
            $verify->entry();
    }
    //验证码
    public function send_sms(){
        vendor('sms.httpUtil');
        $http= new \httpUtil;
        $funAndOperate = "industrySMS/sendSMS";
        // 参数详述请参考http://miaodiyun.com/https-xinxichaxun.html
        // 生成body
        $body = $http->createBasicAuthData();
        $code=mt_rand(1000,9999);
        // 在基本认证参数的基础上添加短信内容和发送目标号码的参数
        $body['smsContent'] = "【惠民科技】您的验证码为".$code."，请于15分钟内正确输入，如非本人操作，请忽略此短信。";
        $body['to'] = I('post.phone');
        $result =  $http->post($funAndOperate, $body);
        $data= json_decode($result,ture)['respCode'];
        echo ($data==00000)?1:0;
        //echo $data;

    }
    /**
     * 获取商品id获取规格项表对应的规格数据
     *
     * @return void
     * @author
     **/
    function getSpec()
    {
        $id=i('get.id');
       $spec_item= D('spec')->relation('spec_item')->where("g_type_id=$id")->select();
       $this->ajaxReturn($spec_item);

    }
    /**
     * 追加规格
     *
     * @return void
     * @author
     **/
    function append_spec()
    {

        //判断缓存是否存有值
        if(s('spec_item')){
            $spec_item=s('spec_item');//取出原来的缓存数据
            $spec_item[i('post.spec_rule')]=i('post.');//添加新数据到缓存数组里面
            $spec_item=array_reverse($spec_item);

        }else{
            //如果没值则录入post的值
             $spec_item[i('post.spec_rule')]=i('post.');

        }
        s('spec_item',$spec_item);
        $this->ajaxReturn(s('spec_item'));
    }
}